package main

import (
	"fmt"
	"github.com/patrickmn/go-cache"
	"time"
)

var Cache = cache.New(5*time.Minute, 10*time.Minute)

func init() {
	fmt.Println("cache init")
}

func setCache(key string, db Database) {
	Cache.Set(key, db, cache.NoExpiration)
}

func getCache(key string) (Database, bool) {
	var found bool
	var db Database
	data, found := Cache.Get(key)
	if found {
		db = data.(Database)
	}
	return db, found
}

func setCacheTable(key string, db TableRuler) {
	Cache.Set(key, db, cache.NoExpiration)
}

func getCacheTable(key string) (TableRuler, bool) {
	var found bool
	var tb TableRuler
	data, found := Cache.Get(key)
	if found {
		tb = data.(TableRuler)
	}
	return tb, found
}
